﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MineDiscover.Interfaces;
using System.Collections;

namespace MineDiscover
{
    public class TileFactory
    {
        private static readonly Object _lock = new Object();
        private TileFactory()
        {
            RegisterTileStyle(TileStyle.TileDraw, typeof(TileDraw));
            RegisterTileStyle(TileStyle.TileImage, typeof(TileImage));
        }

        private static TileFactory Instance;

        public static TileFactory GetInstance()
        {
            lock (_lock)
            {
                if (Instance == null)
                {
                    Instance = new TileFactory();
                }
                return Instance;
            }
        }

        private Hashtable ListTileStyle = new Hashtable();
        
        public void RegisterTileStyle(TileStyle tileStyle, Type type)
        {
            if (ListTileStyle[tileStyle] == null)
            {
                ListTileStyle.Add(tileStyle, type);
            }
        }

        public ITileStyle GetTileStyle(TileStyle tileStyle)
        {
            if (ListTileStyle[tileStyle] == null)
            {
                return null;
            }

           return (ITileStyle)Activator.CreateInstance(ListTileStyle[tileStyle] as Type);
        }
    }
}
